import {
  q as d,
  p as j,
  ap as N,
  X as v,
  f as R,
  H as A,
  av as y,
  aw as D,
  k as _,
  l as b,
  as as s,
  aX as F,
  at as u,
  au as H,
  aY as z,
  ak as $,
  aH as K,
  aZ as x,
  aA as X,
  ay as Y
} from "./index-30f27935.js";
function q(i) {
  return (
    typeof i == "function" ||
    (Object.prototype.toString.call(i) === "[object Object]" && !Y(i))
  );
}
function P(i) {
  const g = d([]),
    o = d(!0),
    l = d({}),
    m = d();
  j();
  const I = N("reload"),
    f = v({
      pageSize: 10,
      currentPage: 1,
      pageSizes: [10, 20, 30],
      total: 0,
      align: "right",
      background: !0,
      small: !1
    }),
    S = v({
      text: "正在加载第一页...",
      viewBox: "-10, -10, 50, 50",
      spinner: `
        <path class="path" d="
          M 30 15
          L 28 17
          M 25.61 25.61
          A 15 15, 0, 0, 1, 15 30
          A 15 15, 0, 1, 1, 27.99 7.5
          L 15 15
        " style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"/>
      `
    }),
    B = [
      {
        type: "selection",
        width: 55,
        align: "left",
        hide: ({ checkList: e }) => !e.includes("勾选列")
      },
      {
        label: "序号",
        type: "index",
        width: 70,
        hide: ({ checkList: e }) => !e.includes("序号列")
      },
      { label: "管理员ID", prop: "admin_id", minWidth: 100 },
      { label: "管理员账号", prop: "admin_name", minWidth: 120 },
      { label: "管理员昵称", prop: "admin_nick", minWidth: 120 },
      {
        label: "角色",
        prop: "role_name",
        minWidth: "100",
        formatter: ({ role_name: e }) =>
          _(
            b("el-tag"),
            { class: "mx-1", type: "success", effect: "light" },
            q(e) ? e : { default: () => [e] }
          )
      },
      {
        label: "状态",
        minWidth: 60,
        cellRenderer: e => {
          var t;
          return _(
            b("el-switch"),
            {
              loading: (t = l.value[e.index]) == null ? void 0 : t.loading,
              modelValue: e.row.admin_status,
              "onUpdate:modelValue": n => (e.row.admin_status = n),
              "active-value": 1,
              "inactive-value": 2,
              "active-text": "已启用",
              "inactive-text": "已禁用",
              "on-color": "#ffff",
              "inline-prompt": !0,
              onChange: () => L(e)
            },
            null
          );
        }
      },
      { label: "操作", fixed: "right", width: 260, slot: "operation" }
    ],
    w = R(() => [
      "!h-[20px]",
      "reset-margin",
      "!text-gray-500",
      "dark:!text-white",
      "dark:hover:!text-primary"
    ]);
  async function C(e) {
    const t = { admin_id: e.admin_id },
      n = JSON.stringify(t),
      c = { value: s.enc.Base64.stringify(s.enc.Utf8.parse(n)) },
      a = await F(c);
    a.code == 200
      ? (u("删除成功", { type: "success" }), I())
      : u(a.msg, { type: "error" });
  }
  function J() {}
  function U(e) {}
  function k(e) {}
  function O(e) {}
  function V(e) {
    (S.text = `正在加载第${e}页...`),
      (o.value = !0),
      y(600).then(() => {
        o.value = !1;
      });
  }
  function L({ row: e, index: t }) {
    H.confirm(
      `确认要<strong>${
        e.admin_status === 0 ? "启用" : "停用"
      }</strong><strong style='color:var(--el-color-primary)'>${
        e.admin_name
      }</strong>角色吗?`,
      "系统提示",
      {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        dangerouslyUseHTMLString: !0,
        draggable: !0
      }
    )
      .then(() => {
        l.value[t] = Object.assign({}, l.value[t], { loading: !0 });
        const n = { admin_id: e.admin_id, admin_status: e.admin_status },
          r = JSON.stringify(n),
          a = { value: s.enc.Base64.stringify(s.enc.Utf8.parse(r)) };
        z(a),
          setTimeout(() => {
            (l.value[t] = Object.assign({}, l.value[t], { loading: !1 })),
              u("已成功修改角色状态", { type: "success" });
          }, 300);
      })
      .catch(() => {
        e.admin_status === 1 ? (e.admin_status = 2) : (e.admin_status = 1);
      });
  }
  async function M(e) {
    var h;
    (o.value = !0), (m.value = e);
    const t = (h = $().getItem(K)) == null ? void 0 : h.role_id,
      r = JSON.stringify({ role_id: e, role: t }),
      a = { value: s.enc.Base64.stringify(s.enc.Utf8.parse(r)) },
      { data: p } = await x(a);
    (g.value = p.data),
      (f.total = p.total),
      setTimeout(() => {
        o.value = !1;
      }, 500);
  }
  async function T() {
    const t = { role: X().role_id, role_id: m.value },
      n = JSON.stringify(t),
      c = { value: s.enc.Base64.stringify(s.enc.Utf8.parse(n)) },
      a = await x(c);
    a.code === 200
      ? ((g.value = a.data.data),
        (f.total = a.data.total),
        setTimeout(() => {
          o.value = !1;
        }, 500))
      : u(a.msg, { type: "error" });
  }
  const W = e => {
    e && (e.resetFields(), location.reload());
  };
  return (
    A(() => {
      y().then(() => {
        const { setWatermark: e } = D(i.value.getTableDoms().tableWrapper);
        e("后台项目", {
          font: "16px Microsoft YaHei",
          globalAlpha: 0.8,
          forever: !0,
          width: 252,
          height: 80
        });
      }),
        T();
    }),
    {
      loading: o,
      columns: B,
      dataList: g,
      pagination: f,
      buttonClass: w,
      onSearch: M,
      resetForm: W,
      handleaddUser: J,
      handleDelete: C,
      handleSizeChange: U,
      handleCurrentChange: k,
      handleSelectionChange: O,
      onCurrentChange: V
    }
  );
}
export { P as useRole };
